#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "clsv.h"
#include "error.h"

void
		myError(int code)
{
	char msg[MAX_ERROR+1];


	switch(code)
	{
		case ERROR_MALLOC:
			strcpy(msg, "Error: Memory allocation error.\n");
			break;
		case INCON_OPC:
			strcpy(msg, "Error: Inconsistent operation code during"
					" operation process.\n");
			break;

		case ERROR_SERVER:
			strcpy(msg, "Error: Internal server error."
					" Please try again\n");
			break;

		case ERROR_LIST:
			strcpy(msg, "Error: Inconsistent list in the server.\n");
			break;

		case ERROR_LISTS:
			strcpy(msg, "Error: Can't get session list.\n");
			break;

		case ERROR_SESS_NOT_EXISTS:
			strcpy(msg, "Error: The requested session does not exist.\n");
			break;

		case ERROR_CONN:
			strcpy(msg, "Error: Can't connect to the required session.\n");
			break;

		case ERROR_NICK_EXISTS:
			strcpy(msg, "Error: A user with the same nick exists for "
					"the required session.\n");
			break;

		case ERROR_ADDING_USER:
			strcpy(msg, "Error: Can't add user to session list.\n");
			break;

		case ERROR_NO_SESSION:
			strcpy(msg, "Error: There are no sessions active in the server"
					" .\n");
			break;

		case ERROR_CHAT:
			strcpy(msg, "Error: Internal server error while processing chat"
					" message.\n");
			break;

		case ERROR_NO_USERS:
			strcpy(msg, "Error: There are no users in the selected session."
					"\n");
			break;

		default:
			strcpy(msg, "Error: Unknown error.\n");
	}

	fprintf(stderr, msg);

	return;
}


void
fatal(char * s)
{
	perror(s);
	exit(EXIT_FAILURE);
}
